#include<iostream>
using namespace std;
#include <string>
#include <algorithm>
class Solution
{
public:
    string reverseStr(string s, int k)
    {
        int count = 0;
        for (int i = 0; i < s.size(); i++)
        {
            count++;
            if (count == 2 * k)
            {
                reverse(s.begin(), s.begin() + k - 1);
                int left = s.size() - 2 * k;
                if (left < k) reverse(s.begin() + 2 * k, s.end() - 1);
                if (left < 2 * k && left >= k)reverse(s.begin() + 2 * k, s.begin() + 2 * k + k - 1);
            }
        }
        return s;
    }
};
int main()
{
    Solution a;
    string s("abcdefg");
    a.reverseStr(s, 2);
	return 0;
}